package tweeter_parser;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

public class SingleFollowerParser {

	Integer myID;
	Collection<Integer> participants;	
	List<Integer> registrations;


	public SingleFollowerParser(String filepath, Collection<Integer> world)
	{
		participants = world;
		registrations = new ArrayList<Integer>();
		try{
			parse(filepath);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	private void parse(String filepath) throws NumberFormatException, IOException
	{
		File f = new File(filepath);
		myID = Integer.parseInt(f.getName().split("_")[0]);
		// Get the object of DataInputStream
		FileInputStream fstream = new FileInputStream(filepath);
		DataInputStream in = new DataInputStream(fstream);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		String strLine;
		// I am not part of this experiment... no need to work hard. 
		if(!participants.contains(myID))
			return;
		registrations.add(myID);
		while ((strLine = br.readLine()) != null)   {
			Integer candidate = Integer.parseInt(strLine);
			if(participants.contains(candidate))
				registrations.add(candidate);
		}

	}
}
